<template>
	<view class="daiban">
		<view class="daibanbox">

		</view>
		<view class="headertop" :style="{'background':back1}">
			<view class="box"
				:style="{'margin-top':statusBarHeight+'px','width':'100%','height':barHeight+'px','display':'flex','align-items': 'center'}">
				<!-- 	<image :src=" _static('/images/LOGO@2x.png')" class="pagelefticon"
					mode="widthFix"></image> -->
			</view>
		</view>
		<view class="" :style="{'margin-top':statusBarHeight+'px','width':'100%','height':barHeight+'px'}">

		</view>
		<view class="rili">
			<image
				:src="typestr=='week'? _static('/images/Group 11698@2x(1).png'):_static('/images/Group 11698@2x.png')"
				class="riliback" mode="widthFix"></image>
			<week-fold-calendar @openfun="openfun" @qiehuan="qiehuan" @change="change" :dots="dots"
				:custom-style="customStyle" active-color="#2AB3F5"></week-fold-calendar>
		</view>
		<view class="titleline">
			<view class="leftbt">
				<image :src="_static('/images/Group 11682@2x(1).png')" class="img1" mode=""></image>
				<span>本{{typestr=='week'?'周':'月'}}待办事项</span>
			</view>
			<view class="rightbz">
				<view class="itemtt">
					<image :src="_static('/images/Ellipse 2647@2x.png')" class="icon" mode=""></image>
					<span>未执行</span>
				</view>
				<view class="itemtt" style="margin-left: 20rpx;">
					<image :src="_static('/images/Star 3@2x.png')" class="icon" mode=""></image>
					<span>已执行</span>
				</view>
			</view>
		</view>
		<view class="msgicon" v-if="Array.isArray(list)">
			<image :src="_static('/images/wxnone.png')" mode="widthFix">
			</image>
			<view class="msgtext">
				暂无内容
			</view>
		</view>
		<view class=""
			style="width:686rpx ;display: flex;justify-content: space-between;margin: auto;height: var(--header-height);"
			v-else>
			<view class="lineleft">
				<view class="line" v-for="(item,index) in list" :key="index">

				</view>
			</view>

			<div class="vertical-steps-flex">

				<div class="step-flex" v-for="(item,index) in list" :key="index">
					<view class="datebox">
						<view class="ziti">
							<span>{{riqifun(index)}}</span>
							<span>月</span>
							<span>{{riqifun1(index)}}</span>
							<span>日</span>
						</view>
					</view>
					<image
						:src="list[index]['status']==1?_static('/images/Star 3@2x.png'):_static('/images/Ellipse 2647@2x.png')"
						class="icon" mode=""></image>
					<view class="texts">
						<view class="t1">
							{{list[index]['title']}}
						</view>
						<view class="t2">
							{{list[index]['describe']}}
						</view>
					</view>
					<div class="step-header">
						<div class="step-number">
							<view class="reduce">
							</view>
						</div>
					</div>
				</div>

			</div>
		</view>

		<view class="" style="height: 200rpx;">

		</view>
		<Tabbar page="/pages/daiban/index"></Tabbar>
	</view>
</template>

<script setup>
	import Tabbar from '@/components/tabbar.vue'
	import WeekFoldCalendar from '@/components/week-fold-calendar/week-fold-calendar.vue';

	import {
		getCurrentInstance,
		onMounted,
		ref,
		reactive
	} from 'vue'
	import {
		onLoad,
		onShow,
		onPageScroll,
		onReachBottom
	} from "@dcloudio/uni-app";
	import {
		setToken,
		getToken,
	} from '@/ulm/utils/auth';
	import {
		_static
	} from '@/ulm/utils/url.js'
	import ulm, {
		$api
	} from '@/ulm';
	const barHeight = ref('')
	const typestr = ref('')
	const list = ref([])
	const back1 = ref('')
	const formData = reactive({
		type: 'month',
		year: '',
		month: '',
		start_date: '',
		end_date: ''
	})
	const dots = ref([{
		date: '2024-07-20',
		value: 1
	}, ])
	const customStyle = ref({
		fontSize: '28rpx',
		color: '#fff',
		fontWeight: 'normal',
		background: 'none',
	})
	const statusBarHeight = ref('')
	onShow(() => {
		const now = new Date
		const month = now.getMonth() + 1; // 月份从0开始，需要+1
		const year = now.getFullYear();
		formData['month'] = month
		formData['year'] = year
		if (getToken()) {
			init()
		}
	})

	function riqifun(str) {
		var arr = str.split('-')
		return arr[1] * 1
	}

	function riqifun1(str) {
		var arr = str.split('-')
		return arr[2] * 1
	}
	async function init() {
		const res = await $api.daibanlist(formData)
		if (res.code == 1) {
			list.value = res.data

			var arr = []
			for (var i in res.data) {
				var obj = {
					date: i,
					value: 1,
					status: res.data[i]['status']
				}
				arr.push(obj)
			}
			dots.value = arr
		}


	}
	onMounted(() => {
		statusBarHeight.value = uni.getSystemInfoSync().statusBarHeight
		const {
			top,
			height
		} = wx.getMenuButtonBoundingClientRect();
		barHeight.value = height ? height + (top - statusBarHeight.value) * 2 : 38;
	})

	onPageScroll((e) => {
		if (e.scrollTop > 100) {
			back1.value = '#CAEEFF'
		} else {
			back1.value = ''
		}
	})

	function change(date) {
		if (typestr.value == 'week') {

		} else {
			var str = date.split('-')
			formData['month'] = str[1] * 1
			formData['year'] = str[0] * 1
		}
		init()
	}

	function qiehuan(e) {
		const {
			current,
			days
		} = e

		if (typestr.value == 'week') {
			formData['start_date'] = days[0]['date']
			formData['end_date'] = days[days.length - 1]['date']
		}
		var riqi = current + ''
		var arr = riqi.split('-')
		formData['year'] = arr[0]
		formData['month'] = arr[1]
	}

	function openfun(e) {
		const {
			viewType,
			days
		} = e
		formData['type'] = viewType
		typestr.value = viewType
		if (typestr.value == 'week') {
			formData['start_date'] = days[0]['date']
			formData['end_date'] = days[days.length - 1]['date']
		} else {
			formData['start_date'] = ''
			formData['end_date'] = ''
		}
		init()
	}
</script>

<style lang="scss">
	.msgicon {
		width: 608rpx;
		margin: 100rpx auto;
		overflow: hidden;

		.msgtext {
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 28rpx;
			color: #86909C;
			text-align: center;
			width: 100%;
			margin-top: 30rpx;
		}

		image {
			width: 608rpx;
		}
	}

	.titleline {
		width: 686rpx;
		margin: auto;
		margin-top: 28rpx;
		margin-bottom: 32rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;

		.leftbt {
			display: flex;
			align-items: center;
			font-weight: bold;
			font-size: 32rpx;
			color: #1D2129;

			.img1 {
				width: 34rpx;
				height: 20rpx;
				margin-right: 14rpx;
			}
		}

		.rightbz {
			display: flex;
			align-items: center;
			font-weight: 400;
			font-size: 24rpx;
			color: #86909C;

			.itemtt {
				display: flex;
				align-items: center;

				.icon {
					width: 20rpx;
					height: 20rpx;
					margin-right: 8rpx;
				}
			}
		}
	}

	.lineleft {
		width: 2rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		margin-top: 96rpx;

		.line {
			background: #E9EAEB;
			width: 2rpx;
			height: 168rpx;
			z-index: -1;
		}
	}

	.vertical-steps-flex {
		display: flex;
		flex-direction: column;
		position: relative;
		width: 646rpx;
		z-index: 99;
	}

	.step-flex {
		width: 646rpx;
		height: 160rpx;
		position: relative;
		background: #FFFFFF;
		box-shadow: 0rpx 0rpx 18rpx 0rpx rgba(0, 0, 0, 0.06);
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		margin-bottom: 32rpx;
		z-index: 99;
		display: flex;
		align-items: center;

		.datebox {
			width: 62rpx;
			padding: 24rpx 0;
			background: #2AB4F5;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #FFFFFF;
			display: flex;
			justify-content: center;
			align-items: center;

			.ziti {
				// text-align: center;
				line-height: 28rpx;
				display: flex;
				flex-direction: column;
				align-items: center;
				font-size: 28rpx;
			}


		}

		.icon {
			width: 20rpx;
			height: 20rpx;
			position: absolute;
			right: 5%;
			top: 20%;
		}

		.texts {
			width: 548rpx;
			margin-left: 18rpx;
			overflow: hidden;
			position: relative;


			.t1 {
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 28rpx;
				color: #1D2129;
				overflow: hidden;
				text-overflow: ellipsis; //文本溢出显示省略号
				white-space: nowrap; //文本不会换行
				width: 100%;
			}

			.t2 {
				font-weight: 400;
				font-size: 26rpx;
				color: #4E5969;
				overflow: hidden;
				text-overflow: ellipsis;
				display: -webkit-box;
				-webkit-line-clamp: 2;
				-webkit-box-orient: vertical;
				margin-top: 12rpx;
			}
		}
	}

	// .step-flex.active {
	// 	background: #f1f8e9;
	// 	border-left: 3px solid #4CAF50;
	// }

	.step-header {
		display: flex;
		align-items: center;
		gap: 10px;
		margin-bottom: 8px;
		z-index: 99;
	}

	.step-number {
		padding: 4rpx;
		background: rgba(181, 181, 181, 0.22);
		border-radius: 50%;
		position: absolute;
		left: -50rpx;
		top: 50%;
		z-index: 99;

		.reduce {
			width: 14rpx;
			height: 14rpx;
			background: #BABABA;
			border-radius: 50%;
		}
	}

	.step-flex.active .step-number {
		// background: #4CAF50;
	}

	// /* 连接线 */
	// .vertical-steps-flex::after {
	// 	content: '';
	// 	z-index: -1;
	// 	position: absolute;
	// 	left: -40rpx;
	// 	top: 100rpx;
	// 	bottom: 50rpx;
	// 	width: 2px;
	// 	background: #E9EAEB;
	// }


	.daiban {
		width: 100%;
		overflow: hidden;
		position: relative;

		.daibanbox {
			width: 100%;
			height: 446rpx;
			background: linear-gradient(180deg, #CAEEFF 71%, rgba(240, 250, 255, 0) 100%);
			border-radius: 0rpx 0rpx 0rpx 0rpx;
			position: absolute;
			z-index: -1;

		}

		.headertop {
			width: 100%;
			position: fixed;
			top: 0%;
			overflow: hidden;
			transition: 0.5s;
			z-index: 9999;
		}

		.pagelefticon {
			width: 120rpx;
			height: 40rpx;
			z-index: 9999;
			margin-left: 30rpx;
		}

		.rili {
			width: 686rpx;
			overflow: hidden;
			margin: auto;
			position: relative;

			.riliback {
				width: 100%;
				height: 614rpx;
				position: absolute;
			}
		}
	}
</style>